package com.darren.euc.dao.impl;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.ContractTemplateDao;
import com.darren.euc.entity.ContractTemplate;


@Repository
public class ContractTemplateDaoImpl extends BaseDaoImpl<ContractTemplate, Integer> implements ContractTemplateDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ContractTemplate> getAll() {
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery("from ContractTemplate where enable=true").list();
	}

	
	@SuppressWarnings("unchecked")
	@Override
	public List<ContractTemplate> getAllEnable() {
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery(" from ContractTemplate where enable=true and status = 1 ").list();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ContractTemplate> getAvaliableContractTemplateByType(String TempleteType) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ContractTemplate where contractType = ? and enable=true and status = 1 ");
		query.setParameter(0, TempleteType);
		return query.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ContractTemplate> getAvaliableContractTemplateBySpaceId(Integer spaceId) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ContractTemplate where spaceId = ? and enable=true and status = 1 ");
		query.setParameter(0, spaceId);
		return query.list();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ContractTemplate> getEnableContractTemplateBySpaceIdNotEquelsId(Integer spaceId,Integer templateid,Integer contractType){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ContractTemplate where spaceId = ? and enable=true and status = 1 and id <> ? and contractType = ? ");
		query.setParameter(0, spaceId);
		query.setParameter(1, templateid);
		query.setParameter(2, contractType);
		return query.list();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ContractTemplate> getAvaliableAll() {
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery("from ContractTemplate where enable=true and status = 1 ").list();
	}
	
}